import request from '@/utils/request'
import { ObjToQueryString } from '@/utils/method'
const baseUrl = process.env.VUE_APP_BASE_API

// 优惠券
export const getCouponList = (params) => {
  return request({
    url: '/coupon/getCouponList',
    params,
    method: 'get'
  })
}
export const getCoupon = (params) => {
  return request({
    url: '/coupon/getCoupon',
    params,
    method: 'get'
  })
}
export const addCoupon = (data) => {
  return request({
    url: '/coupon/addCoupon',
    data,
    method: 'post'
  })
}
export const pushMessage = (id) => {
  return request({
    url: `/coupon/pushMessage/${id}`,
    method: 'post'
  })
}
export const updatePauseButton = (data) => {
  return request({
    url: '/coupon/updatePauseButton',
    data,
    method: 'post'
  })
}
export const updateCoupon = (data) => {
  return request({
    url: '/coupon/updateCoupon',
    data,
    method: 'post'
  })
}
export const deleteCoupon = (id) => {
  return request({
    url: `/coupon/${id}`,
    method: 'delete'
  })
}
// 渠道管理-邀请码
export const getChannel = (params) => {
  return request({
    url: '/channel',
    params,
    method: 'get'
  })
}
export const addChannel = (data) => {
  return request({
    url: '/channel',
    data,
    method: 'post'
  })
}
export const updateChannel = (data) => {
  return request({
    url: '/channel',
    data,
    method: 'put'
  })
}
export const channelInvitationCode = (params) => {
  return request({
    url: '/statistics/channel/invitationCode',
    params,
    method: 'get'
  })
}
export const channelInvitationCodeExport = (params) => {
  const url = '/statistics/channel/invitationCode/export'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
export const getChannelBranch = (params) => {
  return request({
    url: '/channel/branch',
    params,
    method: 'get'
  })
}
export const addChannelBranch = (data) => {
  return request({
    url: '/channel/branch',
    data,
    method: 'post'
  })
}
export const updateChannelBranch = (data) => {
  return request({
    url: '/channel/branch',
    data,
    method: 'put'
  })
}
export const invitationCode = (params) => {
  return request({
    url: `/channel/branch/invitationCode/${params}`,
    method: 'get'
  })
}
export const unUsedQuantity = (params) => {
  return request({
    url: `channel/branch/invitationCode/unUsedQuantity/${params}`,
    method: 'get'
  })
}
export const channelBranchExport = (params) => {
  const url = '/channel/branch/export'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
export const generate = (params) => {
  const url = `/channel/branch/invitationCode/generate/${params.channelId}`
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
export const channelBranchImport = (data) => {
  return request({
    url: `/channel/branch/import/${data.get('channelId')}`,
    data,
    method: 'post'
  })
}
export const getChannelH5 = (params) => {
  return request({
    url: '/channel/h5s',
    params,
    method: 'get'
  })
}
export const addChannelH5 = (data) => {
  return request({
    url: '/channel/h5',
    data,
    method: 'post'
  })
}
export const updateChannelH5 = (data) => {
  return request({
    url: `/channel/h5/${data.id}`,
    data,
    method: 'put'
  })
}
export const getChannelH5Data = (params) => {
  return request({
    url: '/statistics/channel/h5',
    params,
    method: 'get'
  })
}
export const channelH5DataExport = (params) => {
  const url = '/statistics/channel/h5/export'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
export const channelAfData = (params) => {
  return request({
    url: '/statistics/channel/af',
    params,
    method: 'get'
  })
}
export const channelAfDataExport = (params) => {
  const url = '/statistics/channel/af/export'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
export const channelAfDayData = (params) => {
  return request({
    url: '/statistics/channel/af/day',
    params,
    method: 'get'
  })
}
export const channelAfDayDataExport = (params) => {
  const url = '/statistics/channel/af/day/export'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
export const gaDetail = (params) => {
  return request({
    url: 'statics/ga/detail',
    params,
    method: 'get'
  })
}
export const gaDetailExport = (params) => {
  const url = '/statics/ga/detail/export'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
export const gaTotal = (params) => {
  return request({
    url: 'statics/ga/total',
    params,
    method: 'get'
  })
}
export const gaTotalExport = (params) => {
  const url = '/statics/ga/total/export'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
export const gaPackage = () => {
  return request({
    url: '/statics/ga/package',
    method: 'get'
  })
}
export const gaChannel = (params) => {
  return request({
    url: '/gachannel',
    params,
    method: 'get'
  })
}
export const addGaChannel = (data) => {
  return request({
    url: '/gachannel',
    data,
    method: 'post'
  })
}
export const gaChannelExport = (params) => {
  const url = '/gachannel/export'
  if (params) {
    const data = ObjToQueryString(params)
    window.location.href = baseUrl + url + '?' + data.slice(0, -1)
  } else {
    window.location.href = baseUrl + url
  }
}
// 推荐列表
export const getRecommend = (params) => {
  return request({
    url: '/homepage/recommends',
    params,
    method: 'get'
  })
}
export const addRecommend = (data) => {
  return request({
    url: '/homepage/recommend',
    data,
    method: 'post'
  })
}
export const updateRecommend = (data) => {
  return request({
    url: `/homepage/recommend/${data.get('id')}`,
    data,
    method: 'post'
  })
}
export const deleteRecommend = (id) => {
  return request({
    url: `/homepage/recommend/${id}`,
    method: 'delete'
  })
}
// 弹窗广告
export const getPushWay = () => {
  return request({
    url: '/advertising/popUpWindow/pushWay',
    method: 'get'
  })
}
export const setPushWay = (data) => {
  return request({
    url: '/advertising/popUpWindow/pushWay',
    data,
    method: 'put'
  })
}
export const getPopUP = () => {
  return request({
    url: '/advertising/popUpWindows',
    method: 'get'
  })
}
export const addPopUP = (data) => {
  return request({
    url: '/advertising/popUpWindow',
    data,
    method: 'post'
  })
}
export const updatePopUP = (data) => {
  return request({
    url: '/advertising/popUpWindow',
    data,
    method: 'post'
  })
}
export const deletePopUP = (id) => {
  return request({
    url: `/advertising/popUpWindow/${id}`,
    method: 'delete'
  })
}
export const popUPMoveUp = (data) => {
  return request({
    url: `/advertising/popUpWindow/moveUp/${data.id}`,
    data,
    method: 'patch'
  })
}
export const popUPMoveDown = (data) => {
  return request({
    url: `/advertising/popUpWindow/moveDown/${data.id}`,
    data,
    method: 'patch'
  })
}
// 闪屏广告
export const getPushWaySplashScreen = () => {
  return request({
    url: '/advertising/splashScreen/pushWay',
    method: 'get'
  })
}
export const setPushWaySplashScreen = (data) => {
  return request({
    url: '/advertising/splashScreen/pushWay',
    data,
    method: 'put'
  })
}
export const getSplashScreen = () => {
  return request({
    url: '/advertising/splashScreens',
    method: 'get'
  })
}
export const addSplashScreen = (data) => {
  return request({
    url: '/advertising/splashScreen',
    data,
    method: 'post'
  })
}
export const updateSplashScreen = (data) => {
  return request({
    url: '/advertising/splashScreen',
    data,
    method: 'post'
  })
}
export const deleteSplashScreen = (id) => {
  return request({
    url: `/advertising/splashScreen/${id}`,
    method: 'delete'
  })
}
export const splashScreenMoveUp = (data) => {
  return request({
    url: `/advertising/splashScreen/moveUp/${data.id}`,
    data,
    method: 'patch'
  })
}
export const splashScreenMoveDown = (data) => {
  return request({
    url: `/advertising/splashScreen/moveDown/${data.id}`,
    data,
    method: 'patch'
  })
}
// 用户反馈
export const getFeedBack = (params) => {
  return request({
    url: '/online/communication/experiences',
    params,
    method: 'get'
  })
}
export const getFeedBackInfo = (id) => {
  return request({
    url: `/online/communication/experience/${id}`,
    method: 'get'
  })
}
export const updateFeedBackInfo = (data) => {
  return request({
    url: '/online/communication/experience/update',
    data,
    method: 'put'
  })
}
// push推送
export const getPush = () => {
  return request({
    url: '/msgPush/BusinessParamConfigQuery',
    method: 'get'
  })
}
// 系统公告
export const getNotice = () => {
  return request({
    url: '/msgPush/noticeQuery',
    method: 'get'
  })
}
export const addMsgPush = (data) => {
  return request({
    url: '/msgPush/add',
    data,
    method: 'post'
  })
}
export const updateMsgPush = (data) => {
  return request({
    url: '/msgPush/update',
    data,
    method: 'post'
  })
}
export const deleteMsgPush = (id) => {
  return request({
    url: `/msgPush/delete/${id}`,
    method: 'get'
  })
}
